#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int d[N], v[N], a[N];

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);

    int T;
    cin >> T;
    while(T--)
    {
        int n, m, L, V, chao = 0;
        cin >> n >> m >> L >> V;
        for(int i = 1; i <= n; i++)
        {
            cin >> d[i] >> v[i] >> a[i];
            if(v[i] + a[i] > V) chao++;
        }
        cout << chao << " " << chao << endl;
    }
    return 0;
}
